package com.czk.gulimall.search.controller;

import com.czk.gulimall.search.service.MallSearchService;
import com.czk.gulimall.search.vo.SearchParamVo;
import com.czk.gulimall.search.vo.SearchResult;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @Author:ChenZhangKun
 * @Date: 2022/1/25 21:48
 */
@Controller
public class SearchController {
    @Resource
    private MallSearchService mallSearchService;

    @GetMapping({"/list.html", "/"})
    public String listPage(SearchParamVo param, Model model, HttpServletRequest request) {
        // 拿到查询条件
        String queryString = request.getQueryString();
        // 设置查询条件
        param.set_queryString(queryString);
        SearchResult result = mallSearchService.search(param);
        model.addAttribute("result", result);
        return "list";
    }
}
